<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id 
 * @property int $userid 用户ID
 * @property int $room_id 房间ID
 * @property string $room_name 房间名称
 * @property string $room_banner 房间封面
 * @property string $match_id 比赛ID
 * @property int $match_time 比赛时间
 * @property int $match_status 比赛状态
 * @property int $column_id 直播类别
 * @property int $session_id 当前直播场次ID
 * @property int $assistant_userid 助理用户ID
 * @property string $announcement 公告
 * @property string $introduce 直播间介绍
 * @property string $room_cover 直播封面
 * @property string $screenshot 最新直播截屏
 * @property int $status 直播状态 1-未开播 2-正在直播 9-已封禁
 * @property int $ban_time 封禁时长 -1 永久封禁
 * @property int $ban_endtime 封禁截止时间
 * @property int $cute_stream_time 上次断流时间
 * @property int $is_virtual 虚拟主播
 * @property int $listorder 排序
 * @property string $push_stream_address 推流地址
 * @property string $play_stream_address 播放地址-flv
 * @property string $play_stream_address2 播放地址-m3u8
 * @property int $visit_history 历史访问
 * @property-read null|User $user 
 * @property-read null|UserModelAnchor $anchor 
 * @property-read null|Play $match 
 * @property-read null|LiveColumn $column 
 * @property-read null|User $assistant 
 */
class Live extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'live';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'room_id', 'room_name', 'room_banner', 'match_id', 'match_time', 'match_status', 'column_id', 'session_id', 'assistant_userid', 'announcement', 'introduce', 'room_cover', 'screenshot', 'status', 'ban_time', 'ban_endtime', 'cute_stream_time', 'is_virtual', 'listorder', 'push_stream_address', 'play_stream_address', 'play_stream_address2', 'visit_history'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'room_id' => 'integer', 'match_time' => 'integer', 'match_status' => 'integer', 'column_id' => 'integer', 'session_id' => 'integer', 'assistant_userid' => 'integer', 'status' => 'integer', 'ban_time' => 'integer', 'ban_endtime' => 'integer', 'cute_stream_time' => 'integer', 'is_virtual' => 'integer', 'listorder' => 'integer', 'visit_history' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select('id', 'nickname', 'username', 'avatar', 'role_id');
    }

    public function anchor(){
        return $this->hasOne(UserModelAnchor::class, 'userid', 'userid');
    }

    public function match(){
        return $this->hasOne(Play::class, 'match_id', 'match_id');
    }

    public function column(){
        return $this->hasOne(LiveColumn::class, 'id', 'column_id');
    }

    public function assistant(){
        return $this->hasOne(User::class, 'id', 'userid')->select('id', 'nickname', 'username', 'avatar');
    }
}
